(function(vc){
    vc.extends({
        propTypes: {
           emitChooseAffiliateRule:vc.propTypes.string,
           emitLoadData:vc.propTypes.string
        },
        data:{
            chooseAffiliateRuleInfo:{
                affiliateRules:[],
                _currentAffiliateRuleName:'',
            }
        },
        _initMethod:function(){
        },
        _initEvent:function(){
            vc.on('chooseAffiliateRule','openChooseAffiliateRuleModel',function(_param){
                $('#chooseAffiliateRuleModel').modal('show');
                vc.component._refreshChooseAffiliateRuleInfo();
                vc.component._loadAllAffiliateRuleInfo(1,10,'');
            });
        },
        methods:{
            _loadAllAffiliateRuleInfo:function(_page,_row,_name){
                var param = {
                    params:{
                        page:_page,
                        row:_row,
                        communityId:vc.getCurrentCommunity().communityId,
                        name:_name
                    }
                };

                //发送get请求
               vc.http.apiGet('affiliateRule.listAffiliateRule',
                             param,
                             function(json){
                                var _affiliateRuleInfo = JSON.parse(json);
                                vc.component.chooseAffiliateRuleInfo.affiliateRules = _affiliateRuleInfo.affiliateRules;
                             },function(){
                                console.log('请求失败处理');
                             }
                           );
            },
            chooseAffiliateRule:function(_affiliateRule){
                if(_affiliateRule.hasOwnProperty('name')){
                     _affiliateRule.affiliateRuleName = _affiliateRule.name;
                }
                vc.emit($props.emitChooseAffiliateRule,'chooseAffiliateRule',_affiliateRule);
                vc.emit($props.emitLoadData,'listAffiliateRuleData',{
                    affiliateRuleId:_affiliateRule.affiliateRuleId
                });
                $('#chooseAffiliateRuleModel').modal('hide');
            },
            queryAffiliateRules:function(){
                vc.component._loadAllAffiliateRuleInfo(1,10,vc.component.chooseAffiliateRuleInfo._currentAffiliateRuleName);
            },
            _refreshChooseAffiliateRuleInfo:function(){
                vc.component.chooseAffiliateRuleInfo._currentAffiliateRuleName = "";
            }
        }

    });
})(window.vc);
